<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css" />
	</head>

	<body>
		<div class="page-content-wrap">
				<form class="layui-form" action="">
					<div class="layui-form-item">
						<div class="layui-inline tool-btn">
							<button class="layui-btn layui-btn-small layui-btn-normal addBtn hidden-xs" data-url="../index/position-add.jsp" ><i class="layui-icon">&#xe654;</i></button>
							<%--<button class="layui-btn layui-btn-small layui-btn-warm listOrderBtn hidden-xs" data-url="/admin/category/listorderall.html"><i class="iconfont">&#xe656;</i></button>--%>
						</div>


					</div>
				</form>
				<div class="layui-form" id="table-list">
					<table class="layui-table" lay-even lay-skin="nob">
						<colgroup>
							<col width="50">
							<col class="hidden-xs" width="50">
							<col class="hidden-xs" width="100">
							<col>
							<col width="80">
							<col width="150">
						</colgroup>
						<thead>
							<tr class="title">
								<th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
								<th >ID</th>
								<th >名称</th>
								<th >描述</th>
								<th>操作</th>

							</tr>
						</thead>
						<tbody>
						<%--<tr>
                            <td><input type="checkbox" name="" lay-skin="primary" ></td>
                            <td class="deptName">1</td>
                            <td class="deptEmail">首页</td>
                            <td class="deptAddress"><td>
                                <div class="layui-inline">
                                    <button class="layui-btn layui-btn-mini layui-btn-normal  add-btn"  data-url="position-update.html"><i class="layui-icon">&#xe654;</i></button>
                                </div>

                            </td>
                        </tr>--%>

						</tbody>
					</table>
				</div>
		</div>
		<script src="https://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script>
		<script src="${pageContext.request.contextPath}/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="${pageContext.request.contextPath}/static/admin/js/common.js" type="text/javascript" charset="utf-8"></script>
		<script>
			$(document).ready(function(){
				showPositionAjax();
			})

			function showPositionAjax(){

				$.ajax({
					async:true,
					url:"${pageContext.request.contextPath}/Position/getPositionByPage",
					type:"POST",
					data:{pageNum:"1",
						pageSize:"15"},
					dataType:"json",
					success:function(result,status,xhr){
						$.each(result.list,function(index,position){
							$("tbody").append("<tr>\n" +
									"                            <td><input type=\"checkbox\" name=\"\" lay-skin=\"primary\" ></td>\n" +
									"                            <td class=\"positionId\">"+position.positionId+"</td>\n" +
									"                            <td class=\"positionName\">"+position.positionName+"</td>\n" +
									"                            <td class=\"describtion\">"+position.describtion+"<td>\n" +
									"                                <div class=\"layui-inline\">\n" +
									"                                    <button  class=\"layui-btn layui-btn-mini layui-btn-normal  add-btn\"  data-url='../index/position-update.jsp?positionId="+position.positionId+"\'><i class=\"layui-icon\">&#xe642;</i></button >\n" +
									"                                </div>\n" +
									"\n" +
									"                            </td>\n" +
									"                        </tr>")
						});

					},
					error:function(xhr,status,error){
						alert("异步请求失败!");
					}
				});

			}

			$(document).on("click",".deleteBtn",function(){
				var positionId = $(this).parents("tr").children("td.positionId").text();

				$.ajax({
					async:true,
					url:"${pageContext.request.contextPath}/Position/deletePositionInfo",
					type:"get",
					data:{
						positionId:positionId
					},
					dataType:"json",
					success:function(result,status,xhr){

						if(result == "1"){
							alert("删除成功");
							$("tr").not(".title").remove();
						}else {
							alert("删除失败");
						}

						showPositionAjax();

					},
					error:function(xhr,status,error){
						alert("异步请求失败!");
					}
				})
			})


			$(document).on("click",".layui-layer-close",function(){
				$("tr").not(".title").remove();
				showPositionAjax();
			})















		</script>
	</body>

</html>